var Data = {
    "code": 0,
    "data": {
        "controlLateralDataMap": {
            "cLateral": {}
        },
        "controlHeadingDataMap": {
            "cHeading": {}
        },
        "controlSpeedDataMap": {
            "cSpeed": {},
            "cSpeedReal": {},
            "cSpeedTarget": {}
        },
        "controlStationDataMap": {
            "cStation": {}
        },
        "controlAccelerationDataMap": {
            "cAcceleration": {},
            "cAccelerationTarget": {},
            "cAccelerationReal": {}
        },
        "executeSteerDataMap": {
            "eSteerReal": {},
            "eSteer": {},
            "eSteerTarget": {}
        },
        "executeAccelerationDataMap": {
            "eAccelerationReal": {},
            "eAccelerationTarget": {},
            "eAcceleration": {}
        }
    },
    "msg": "查询成功"
};

export default function buildList(startTime, endTime, type = "all") {
    //type  :
    // all：全时间段，各个项目数据点位都是满的
    // span：不连续
    // empty:空数据
    console.log("buildList");
    let D = JSON.parse(JSON.stringify(Data));
    Object.keys(D.data).forEach(keyParent => {
        let child = D.data[keyParent]
        Object.keys(child).forEach(keyChild => {
            let start = new Date(startTime).getTime();
            let end = new Date(endTime).getTime();
            let list = [];
            let info = [];
            if (type == "empty") {
                if (Math.random() > 0.5) {
                    return;
                }
            }
            while (start < end) {
                if (type == "all") {

                } else if (type == "span") {
                    if (Math.random() > 0.5) {
                        start += 20;
                        continue;
                    }
                }
                let r = buildData();
                r.dataTime = formatDate(new Date(start), "yyyy-MM-dd HH:mm:ss") + `.` + start.toString().slice(-3);
                list.push(r);
                start += 20;
            }
            info = [buildData()];
            child[keyChild] = {
                list, info
            };
        })
    })
    return D;
}
function buildData() {
    return {
        "error": Math.random() * 10,
        "maximum": Math.random() * 10,
        "minimum": Math.random() * 10,
        "average": Math.random() * 10,
        "variance": Math.random() * 10,
        "dataTime": "",
        "calcFlag": 1,
    };
}

// let result = buildList("2022-02-15 15:14:23", "2022-02-15 15:14:24", "all");

// console.log(result);

function formatDate(date, fmt) {
    date = new Date(date)
    if (typeof (fmt) === 'undefined') {
        fmt = 'yyyy-MM-dd HH:mm:ss'
    }
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
    }
    const o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'H+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds(),
        'S+': date.getMilliseconds()
    }
    for (const k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
            const str = o[k] + ''
            fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : ('00' + str).substr(str.length))
        }
    }
    return fmt
}